﻿Imports System.Windows.Forms

Public Class ChilkatDialog
    Friend UnlockedMessage = "Chilkat FTP is Unlocked"
    Friend LockedMessage As String = "Chilkat FTP is a 30-Day Trial Only"
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        If Main.ChilkatKey <> "30-Day Trial" Then
            Dim FileString As String = Application.StartupPath & "\ChilkatLicence.lnc"
            'Write Settings to file
            My.Computer.FileSystem.WriteAllText(FileString, "Licence = " & Main.ChilkatKey & vbCrLf, False)
        End If

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub ActivateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActivateButton.Click
        If KeyTextBox.Text.Length <> 24 Then
            MessageBox.Show("Key is an invalid length", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            Dim keyattempt As String = KeyTextBox.Text
            success = FTPFunctions.ftp.UnlockComponent(keyattempt)
            'FTPFunctions.ftp.IsUnlocked.TrueString
            If FTPFunctions.ftp.IsUnlocked <> True Then
                MessageBox.Show("Chilkat Key is invalid", "Invalid Key", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                Main.ChilkatKey = keyattempt
                MessageBox.Show("Chilkat FTP has now been unlocked!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
                ActivateButton.Enabled = False
                KeyTextBox.ReadOnly = True
                MessageLabel.Text = UnlockedMessage
            End If
        End If
    End Sub

    Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If FTPFunctions.ftp.IsUnlocked = True Then
            MessageLabel.Text = UnlockedMessage
            ActivateButton.Enabled = False
            KeyTextBox.Text = Main.ChilkatKey
            KeyTextBox.ReadOnly = True
        Else
            MessageLabel.Text = LockedMessage
        End If
    End Sub
End Class
